package com.springBoot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.springBoot.domain.SysDept;
import com.springBoot.mapper.SysDeptMapper;
import com.springBoot.service.ExcelService;
import jakarta.annotation.Resource;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExcelServiceImpl implements ExcelService {
    @Resource
    private SysDeptMapper sysDeptMapper;

    @Override
    public Workbook getExcel() {
        List<SysDept> sysDepts = sysDeptMapper.selectList(null);
        Workbook workbook = new XSSFWorkbook();
        Sheet dept = workbook.createSheet("dept");

        Row row = dept.createRow(0);
        row.createCell(0).setCellValue("id");
        row.createCell(1).setCellValue("pid");
        row.createCell(2).setCellValue("name");
        row.createCell(3).setCellValue("sort");
        row.createCell(4).setCellValue("creator");
        row.createCell(5).setCellValue("create_date");
        row.createCell(6).setCellValue("updater");
        row.createCell(7).setCellValue("update_date");

        int num=1;
        for (SysDept sysDept : sysDepts) {
            dept.createRow(num++);
            row.createCell(0).setCellValue(sysDept.getId());
            row.createCell(1).setCellValue(sysDept.getPid());
            row.createCell(2).setCellValue(sysDept.getName());
            row.createCell(3).setCellValue(sysDept.getSort());
            row.createCell(4).setCellValue(sysDept.getCreator());
            row.createCell(5).setCellValue(sysDept.getCreateDate());
            row.createCell(6).setCellValue(sysDept.getUpdater());
            row.createCell(7).setCellValue(sysDept.getUpdateDate());
        }



        return workbook;
    }
}
